Add wildcard host matching to AllowedHostsValidator - #701
Add wildcard host matching to AllowedHostsValidator#701David Blain (dabla) wants to merge 1 commit into
Conversation
Support wildcard patterns in the allowlist so trusted host groups can be managed without listing every subdomain explicitly. Keep strict host normalization and validation to preserve safe trust decisions.
|
Vincent Biret (baywet)
left a comment
There was a problem hiding this comment.
Thanks for the contribution!
Would you be willing to make the same contribution in other languages to align the behaviour?
|
(also can you please run the formatting command) |
There was a problem hiding this comment.
Pull request overview
This PR extends AllowedHostsValidator (abstractions auth) to support suffix-based “wildcard” allowlist entries (domains prefixed with ".") so callers can allow dynamic subdomains without disabling host validation.
Changes:
- Add suffix matching in
AllowedHostsValidator.is_url_host_valid(...)for allowlist entries that start with"."(subdomain-only). - Add/extend unit tests covering suffix matching behavior, including bare-domain rejection and case-insensitivity.
- Ensure
set_allowed_hosts(...)updates continue to preserve suffix matching behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/abstractions/kiota_abstractions/authentication/allowed_hosts_validator.py | Adds suffix-based allowlist matching while keeping exact-match behavior. |
| packages/abstractions/tests/authentication/test_allowed_hosts_validator.py | Adds test coverage for suffix matching, bare-domain rejection, case-insensitivity, and post-update behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.



Support wildcard patterns in the allowlist so trusted host groups can be managed without listing every subdomain explicitly. Keep strict host normalization and validation to preserve safe trust decisions.
Overview
This PR extends
AllowedHostsValidatorto support wildcard-style host matching via suffix entries (for example,.fabric.microsoft.com) while preserving exact-match behavior.This is needed for APIs that use dynamic or tenant-specific subdomains, where enumerating every hostname is not practical. With this change, callers can keep host validation enabled instead of falling back to an empty allowed_hosts list.
Related Issue
Fixes #700
Demo
Notes
Suffix entries are intentionally subdomain-only:
.fabric.microsoft.commatchesfoo.fabric.microsoft.com.fabric.microsoft.comdoes not matchfabric.microsoft.comExact host entries continue to work as before.
Testing Instructions
pwsh -File .\kiota-python.ps1 testSet-Location .\packages\abstractionspoetry installpoetry run pytest .\tests\authentication\test_allowed_hosts_validator.pyset_allowed_hosts(...)keeps suffix behavior